using System;

namespace Liberate.VSIntergration.Errors
{
    public static class ErrorHandler
    {
        public static void ShowErrors(params Exception[] errors)
        {
            ShowErrors(true, errors);
        }

        public static void ShowErrors(bool clearText, params Exception[] errors)
        {
            if (errors != null && errors.Length > 0)
            {
                if (clearText)
                    OutputWindow.LibernatePane.Clear();
                OutputWindow.LibernatePane.Activate();
                foreach (var error in errors)
                {
                    OutputWindow.LibernatePane.WriteLine("--------------------------------------------");
                    OutputWindow.LibernatePane.WriteLine(error.Message);
                    if (error.InnerException != null)
                    {
                        OutputWindow.LibernatePane.WriteLine("inner exception:");
                        OutputWindow.LibernatePane.WriteLine(error.InnerException.Message);
                    }
                    OutputWindow.LibernatePane.WriteLine("stack trace:");
                    OutputWindow.LibernatePane.WriteLine(error.StackTrace);
                }
                OutputWindow.ShowOutputWindow();
            }
        }
    }
}